
function param(obj) {
	var str = '';
	for (var prop in obj) {
		if (obj.hasOwnProperty(prop)) {
			if (str.length > 0) {
				str += '&';
			}
			str += encodeURI(prop + '=' + obj[prop]);
		}
	}
	return(str);
}

function http_post(url, params, callback) {
	var xhr = new XMLHttpRequest();
	xhr.open('POST', encodeURI(url));
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr.onload = function() {
		var err = false;
		if(xhr.status !== 200) {
			err = true;
		}
		callback(err, xhr.responseText);
	};
	xhr.send(encodeURI(param(params)));
}

function ping(obj) {
	/*var url = (typeof url_ping !== 'undefined') ? url_ping : '/stat/ping';
	http_post(url, obj, function(err, data) {
	});*/
}

function event(id, cb) {
	var url = '/stat/event';
	var params = { id:id };
	http_post(url, params, function(err, data) {
		var r = err ? false : JSON.parse(data);
		cb(r);
	});
}